package com.ruoyi.exchangeCode.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.exchangeCode.mapper.ExchangeCodeMapper;
import com.ruoyi.exchangeCode.domain.ExchangeCode;
import com.ruoyi.exchangeCode.service.IExchangeCodeService;

/**
 * 兑换码Service业务层处理
 * 
 * @author zunzun
 * @date 2023-11-22
 */
@Service
public class ExchangeCodeServiceImpl implements IExchangeCodeService 
{
    @Autowired
    private ExchangeCodeMapper exchangeCodeMapper;

    /**
     * 查询兑换码
     * 
     * @param id 兑换码主键
     * @return 兑换码
     */
    @Override
    public ExchangeCode selectExchangeCodeById(Long id)
    {
        return exchangeCodeMapper.selectExchangeCodeById(id);
    }

    /**
     * 查询兑换码列表
     * 
     * @param exchangeCode 兑换码
     * @return 兑换码
     */
    @Override
    public List<ExchangeCode> selectExchangeCodeList(ExchangeCode exchangeCode)
    {
        return exchangeCodeMapper.selectExchangeCodeList(exchangeCode);
    }

    /**
     * 新增兑换码
     * 
     * @param exchangeCode 兑换码
     * @return 结果
     */
    @Override
    public int insertExchangeCode(ExchangeCode exchangeCode)
    {
        return exchangeCodeMapper.insertExchangeCode(exchangeCode);
    }


    @Override
    public int insertExchangeCodeList(ExchangeCode exchangeCode)
    {
        if(exchangeCode.getAddCount()<=10000) {
            for (int i = 0; i < exchangeCode.getAddCount(); i++) {
                //随机生成10位不重复的兑换码
                exchangeCode.setCode(String.valueOf(Math.round(Math.random() * 10000000000L)));

            }
            exchangeCodeMapper.insertExchangeCode(exchangeCode);
            return 1;
        }
        return 0;
    }


    /**
     * 修改兑换码
     * 
     * @param exchangeCode 兑换码
     * @return 结果
     */
    @Override
    public int updateExchangeCode(ExchangeCode exchangeCode)
    {
        return exchangeCodeMapper.updateExchangeCode(exchangeCode);
    }

    /**
     * 批量删除兑换码
     * 
     * @param ids 需要删除的兑换码主键
     * @return 结果
     */
    @Override
    public int deleteExchangeCodeByIds(Long[] ids)
    {
        return exchangeCodeMapper.deleteExchangeCodeByIds(ids);
    }

    /**
     * 删除兑换码信息
     * 
     * @param id 兑换码主键
     * @return 结果
     */
    @Override
    public int deleteExchangeCodeById(Long id)
    {
        return exchangeCodeMapper.deleteExchangeCodeById(id);
    }
}
